// run: $exec < in
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
#define eps 1e-8
double max(double x, double y)
{
	return x>y?x:y;
}
double min(double x, double y)
{
	return x<y?x:y;
}
struct point {
	double x, y;
	point(){}
	point(double x, double y):x(x), y(y){}
};
struct line{
	point p1, p2;
};
typedef std::vector<point> polygon;
double xmult(point p1, point p2, point p0)
{
	return (p1.x-p0.x)*(p2.y-p0.y) - (p2.x-p0.x)*(p1.y-p0.y);
}
double dis_p2p(point p1, point p2)
{
	return sqrt( (p1.x-p2.x)*(p1.x-p2.x) + (p1.y-p2.y)*(p1.y-p2.y) );
}
int intersect_in(line s1, line s2)
{
	    /*
		 *      * 判断两线段相交, 包括一个线段的一个点在另一个线段上的情况
		 *           * min, max判断保证了判断2线段共线而不想交情况
		 *                * */
	    double x1 = xmult(s2.p1, s1.p2, s1.p1);
		    double x2 = xmult(s2.p2, s1.p2, s1.p1);
			    double x3 = xmult(s1.p1, s2.p2, s2.p1);
				    double x4 = xmult(s1.p2, s2.p2, s2.p1);
					    if(x1*x2<eps && x3*x4<eps && min(s1.p1.x, s1.p2.x)<=max(s2.p1.x, s2.p2.x)
								            && min(s1.p1.y, s1.p2.y)<=max(s2.p1.y, s2.p2.y) && min(s2.p1.x, s2.p2.x)<=max(s1.p1.x, s1.p2.x)
											            && min(s2.p1.y, s2.p2.y)<=max(s1.p1.y, s1.p2.y))
							        return 1;
						    return 0;
}
point intersection(point p1, point p2, point p3, point p4)
{
	    double a1, b1, c1;
		        double a2, b2, c2;
		            a1 = p1.y - p2.y; b1 = p2.x-p1.x; c1 = p1.x*p2.y-p2.x*p1.y;
		                a2 = p3.y-p4.y; b2 = p4.x-p3.x; c2 = p3.x*p4.y- p4.x*p3.y;
		                    point ret;
		                        ret.x = (c2*b1-c1*b2)/(a1*b2-a2*b1);
		                            ret.y = (c1*a2-c2*a1)/(a1*b2-a2*b1);
		                                return ret;
}
double ans;
polygon convexCut(const polygon &poly, const line &s)
{
	polygon q;
	point p1 = s.p1, p2 = s.p2;
	point qs[5];
	int qc = 0;
	int n = poly.size();
	for(int i=0; i<n; i++)
	{
		double c = xmult(p2, poly[i], p1);
		double d = xmult(p2, poly[(i+1)%n], p1);
		if(c >= 0){
			q.push_back(poly[i]);
			if(c == 0)
				qs[qc++] = poly[i];
		}
		if(c*d<0){
			qs[qc++] = intersection(poly[i], poly[(i+1)%n], p1, p2);
			q.push_back(intersection(poly[i], poly[(i+1)%n], p1, p2));
		}
	}
	ans += dis_p2p(qs[0], qs[1]);
	return q;
}
int n;
int a[15];
point p0;
point ps[20];
line ls[20];
polygon poly;
void init()
{
	ans = 0;
	poly.clear();
	poly.push_back(point(0, 0));
	poly.push_back(point(p0.x, 0));
	poly.push_back(point(p0.x, p0.y));
	poly.push_back(point(0, p0.y));
}
int main()
{
	int t;
	scanf("%d", &t);
	for (int ti = 1; ti <= t; ti++) {
		if (ti > 1) printf("\n");
		scanf("%lf%lf", &p0.x, &p0.y);
		scanf("%d", &n);
		for(int i=0; i<n; i++){
			a[i] = i;
			scanf("%lf%lf", &ps[i].x, &ps[i].y);
		}
		for(int i=0; i<n; i++){
			ls[i].p1 = ps[(i+1)%n];
			ls[i].p2 = ps[i];
		}
		double mi = 9e9;
		do{
			init();
			for(int i=0; i<n; i++){
				poly = convexCut(poly, ls[a[i]]);
			}
			mi = min(mi, ans);
		}while(std::next_permutation(a, a+n));

		printf("Minimum total length = %.3f\n", mi);
	}
	return 0;
}
